{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "done\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n",
    "path = 'D:/homework/test'\n",
    "pathNew = 'D:/homework/pre'\n",
    "\n",
    "if os.path.exists(pathNew)!=True:\n",
    "    os.makedirs(pathNew)\n",
    "files = os.listdir(path)\n",
    "\n",
    "for file in files[0:]:\n",
    "    df = pd.read_csv(path+'/'+file,encoding='gbk')\n",
    "    df = df.drop_duplicates()\n",
    "    df.to_csv(pathNew+'/'+file)\n",
    "    \n",
    "print('done')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Unnamed: 0     turID              rectime  iActivePoweiSetPointValue  \\\n",
      "0           0  20003001  2017-03-04 15:38:10                        187   \n",
      "\n",
      "   iAvailabillityToday  iAvailabillityTotal  iBlade1TempBattBox_1sec  \\\n",
      "0                99.99                99.58                     21.2   \n",
      "\n",
      "   iBlade1TempInvBox_1sec  iBlade1TempMotor_1sec  iBlade1TempPMCHeatsink_1sec  \\\n",
      "0                    21.8                   33.9                         33.3   \n",
      "\n",
      "        ...        iBlade1MotorCurrent  iBlade2MotorCurrent  \\\n",
      "0       ...                        NaN                  NaN   \n",
      "\n",
      "   iBlade3MotorCurrent  iPitchSpeedBlade1  iPitchSpeedBlade2  \\\n",
      "0                  NaN                NaN                NaN   \n",
      "\n",
      "   iPitchSpeedBlade3  iWindSpeed_real  iWindSpeed_real_30s  \\\n",
      "0                NaN              NaN                  NaN   \n",
      "\n",
      "   iWindSpeed_real_10min  collectorCount  \n",
      "0                    NaN             NaN  \n",
      "\n",
      "[1 rows x 138 columns]\n"
     ]
    }
   ],
   "source": [
    "data = pd.read_csv('D:/homework/pre/20003001#2017-03.csv')\n",
    "print(data.head(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0, 2, 3, 613, 9, 45, 657, 884, 53, 886, 93, 287}\n"
     ]
    }
   ],
   "source": [
    "print(set(data['WT_Faultcode']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['Unnamed: 0', 'turID', 'rectime', 'iActivePoweiSetPointValue',\n",
      "       'iAvailabillityToday', 'iAvailabillityTotal', 'iBlade1TempBattBox_1sec',\n",
      "       'iBlade1TempInvBox_1sec', 'iBlade1TempMotor_1sec',\n",
      "       'iBlade1TempPMCHeatsink_1sec',\n",
      "       ...\n",
      "       'iBlade1MotorCurrent', 'iBlade2MotorCurrent', 'iBlade3MotorCurrent',\n",
      "       'iPitchSpeedBlade1', 'iPitchSpeedBlade2', 'iPitchSpeedBlade3',\n",
      "       'iWindSpeed_real', 'iWindSpeed_real_30s', 'iWindSpeed_real_10min',\n",
      "       'collectorCount'],\n",
      "      dtype='object', length=138)\n"
     ]
    }
   ],
   "source": [
    "print(data.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "#其中'entercount','TurbineStatus','EnterType'三个字段在归一化的时候\n",
    "#由于最大值和最小值都是一样的，会出现NaN的情况，即没有任何可利用的信息\n",
    "#所以去除该字段\n",
    "dataSetLabel = data[['WT_Faultcode']]\n",
    "dataSetFeature =  data[['iActivePoweiSetPointValue','iAvailabillityToday', 'iAvailabillityTotal', 'iBlade1TempBattBox_1sec', 'iBlade1TempInvBox_1sec', 'iBlade1TempMotor_1sec',\n",
    "                 'iBlade1TempPMCHeatsink_1sec','iBlade1TempPMMHeatsink_1sec','iBlade2TempBattBox_1sec','iBlade2TempInvBox_1sec','iBlade2TempMotor_1sec','iBlade2TempPMCHeatsink_2sec',\n",
    "                  'iBlade2TempPMMHeatsink_2sec','iBlade3TempBattBox_1sec','iBlade3TempInvBox_1sec','iBlade3TempMotor_1sec','iBlade3TempPMCHeatsink_3sec','iBlade3TempPMMHeatsink_3sec',\n",
    "                  'iBPLevel','iCableTwistTotal','iCosPhi','iCosPhiSetValue','iFiequency','iGenPower','iGenSpeed','iIL1_690V','iIL2_690V','iIL3_690V',\n",
    "                    'iKWhOverall_h','iKWhOverall_l','iKWhThisDay_h','iKWhThisDay_l','iNacellePositionLtd','iNacellePositionTotal','iOperationHoursDay',\n",
    "                    'iOperationHoursOverall_h','iOperationHoursOverall_l','iPitchAngle1','iPitchAngle2','iPitchAngle3','iReactivePower','iSetValueGenSpeed',\n",
    "                    'iSetValuePitchAngle','iTemp1GearOil_1sec','iTempCabinetNacelle_1sec','iTempCabinetTowerBase_1sec','iTempCntr_1sec','iTempGearBearDE_1sec',\n",
    "                    'iTempGearBearNDE_1sec','iTempGenBearDE_1sec','iTempGenBearNDE_1sec','iTempGenCoolingAir_1sec','iTempGenStatorU_1sec','iTempGenStatorV_1sec',\n",
    "                     'iTempGenStatorW_1sec','iTempHub_1sec','iTempMV_1sec','iTempNacelle_1sec','iTempOutdoor_1sec','iTempRotorBearA_1sec','iTempRotorBearB_1sec',\n",
    "                    'iTempTowerBase_1sec','iTempTransformer690_400V_1sec','iTurbineOperationMode','iUL1_690V','iUL2_690V','iUL3_690V','iVaneDiiection','iVibrationY',\n",
    "                    'iVibrationZ','iwindDirection','iWindSpeed','iYPLevel','WT_Runcode']]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\software\\envs\\tensorflow\\lib\\site-packages\\ipykernel_launcher.py:27: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n"
     ]
    }
   ],
   "source": [
    "def GenLabel(row):\n",
    "    if row==0:\n",
    "        row=0\n",
    "    elif row==2:\n",
    "        row=1\n",
    "    elif row==3:\n",
    "        row=2\n",
    "    elif row==613:\n",
    "        row=3\n",
    "    elif row==9:\n",
    "        row=4\n",
    "    elif row==45:\n",
    "        row=5\n",
    "    elif row==657:\n",
    "        row=6\n",
    "    elif row==884:\n",
    "        row=7\n",
    "    elif row==53:\n",
    "        row=8\n",
    "    elif row==886:\n",
    "        row=9\n",
    "    elif row==93:\n",
    "        row=10\n",
    "    else:\n",
    "        row=11\n",
    "    return row\n",
    "dataSetLabel['WT_Faultcode'] = dataSetLabel['WT_Faultcode'].apply(GenLabel)\n",
    "print(set(dataSetLabel['WT_Faultcode']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataSetFeature = dataSetFeature.apply(lambda x: (x - np.min(x)) / (np.max(x) - np.min(x)))\n",
    "dataSetFeature.to_csv(pathNew+'/predataFeature.csv',index=0)\n",
    "dataSetLabel.to_csv(pathNew+'/dataLabel.csv',index=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
